// Main program.  Here we need to instantiate objects of class Lap and call member functions

#include <iostream>
#include <vector>
#include "Lap.h"
using namespace std;

int main()
{
   int first_lap, last_lap, num_of_laps, lap_number, i;
//  We will hold pointers to objects of type 'lap' in a vector (a vector of pointers)
//   We use a vector because it's easy to increase the size of a vector
//   We use pointers so that we can sort the elements of the vector without having to
//    copy entire lap objects - we can just change which lap the pointer element is 
//     pointing to 
//  You don't need to do this in the same way I'm doing it, but I suggest it
   vector <Lap *> laps;

//  Find out from user which laps to analyze
   cout << "Enter first lap: ";
   cin >> first_lap; 
   cout << "Enter last lap: ";
   cin >> last_lap; 
//  Number of laps to be analyzed
   num_of_laps = last_lap - first_lap + 1;

   for (i = first_lap; i <= last_lap; i++)
//  We use push_back to add elements to the vector laps.  Remember that 'new' creates an
//   object and returns a pointer to it, which gets appended at the end of the vector
//  In the course of creating the object of class Lap, 
//   the constructor of class Lap gets called with argument i (which is the lap number) 
     laps.push_back( new Lap(i) );


//   Insert code here
   enum OUTS{lapn=0,time,avgsp,gaspct,maxspeed,minspeed,turnen,turnex,used};
   double Output[30][15];

   //GET DATA---------------------------------------------
   for(i = 0; i < num_of_laps; i++)
   {
	   double Turnexit = 0;
	    Output[i][used] = 0;
		Output[i][lapn] = laps[i]->LapN();
		Output[i][time] = laps[i]->LapTime();
		Output[i][avgsp] = laps[i]->AVGTime();
		Output[i][gaspct] = laps[i]->AVGAccel();
		Output[i][maxspeed] = laps[i]->MAXspd();
		Output[i][minspeed] = laps[i]->MINspd();
		Output[i][turnen] = laps[i]->TURNSPD(Turnexit);
		Output[i][turnex] = Turnexit; //turnexit issues
		laps[i]->OUTACCEL(i);

   }
   //PRINT IN ORDER---------------------------------------
   cout << "LAP TIME   AVGSPD   ACCELPCT  MAXSPD  MINSPD  TURNENSPD  TURNEXSPD" << endl;
   //for(int i = first_lap; i <= last_lap; i++)
   for(i = 0; i < num_of_laps; i++)
   {
		double temptime = 500;
		int order;
	   for(int j = 0; j < num_of_laps; j++)
	   {
		   if(Output[j][time] < temptime && Output[j][used] == 0)
		   {
			   order = j;
			   temptime = Output[j][time];
		   }
	   }
	   Output[order][used] = 1;

	   cout << Output[order][lapn] << ", " << Output[order][time] << ", " << Output[order][avgsp] << ", " <<
			Output[order][gaspct] << ", " << Output[order][maxspeed] << ", " << Output[order][minspeed] << ", " <<
			Output[order][turnen] << ", " << Output[order][turnex] << endl;
   }

	int done;
	cin >> done;

//  Delete allocated space
   for (i = 0; i < num_of_laps; i++)
     delete laps[i];  // free up memory allocated with 'new' above, when we're done
 
}
